{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "import torchvision.transforms as transforms\n",
    "import os\n",
    "import numpy as np\n",
    "import torchvision\n",
    "from torch.utils.data import Dataset\n",
    "import torch\n",
    "from torch.utils.data import DataLoader\n",
    "from vit_pytorch import ViT\n",
    "\n",
    "device = torch.device(\"cuda:0\" if torch.cuda.is_available() else \"cpu\")\n",
    "dataset_dir = '/Users/leslie/Desktop/dataset2/'\n",
    "dataset_dir_dog = '/Users/leslie/Desktop/dataset2/Dog'\n",
    "learning_rate = 0.01\n",
    "train_ratio = 0.8\n",
    "batch_size = 64\n",
    "epochs = 10\n",
    "\n",
    "def get_transform():\n",
    "    transform = transforms.Compose([\n",
    "    transforms.ToPILImage(),\n",
    "    transforms.Resize((256, 256)),\n",
    "    transforms.AutoAugment(),\n",
    "    transforms.ToTensor(),\n",
    "    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])\n",
    "    return transform\n",
    "\n",
    "def generate_images_valid(dataset_dir = dataset_dir):\n",
    "\n",
    "    transform = get_transform()\n",
    "    data_dic = {}\n",
    "    class_idx = 0\n",
    "    for folder in os.listdir(dataset_dir):\n",
    "        if folder[0] != \".\":\n",
    "            folder_path = os.path.join(dataset_dir, folder)\n",
    "            for image in os.listdir(folder_path):\n",
    "                if image[-3:] == \"jpg\":\n",
    "                    image_path = os.path.join(folder_path, image)\n",
    "                    data_dic[image_path] = class_idx\n",
    "            class_idx += 1\n",
    "\n",
    "    images_valid = {}\n",
    "\n",
    "    for k,v in data_dic.items():\n",
    "        try:\n",
    "            a = torchvision.io.read_image(k)\n",
    "            transform(a)\n",
    "            images_valid[k] = v\n",
    "        except Exception as e:\n",
    "            print(\">>>>>>>>>>>>>>\")\n",
    "            print(e)\n",
    "            print(\">>>>>>>>>>>>>>\")\n",
    "            pass\n",
    "\n",
    "    np.save('images_valid.npy',images_valid)\n",
    "\n",
    "class ImageDataset(Dataset):\n",
    "    def __init__(self, images_valid, transform=None, target_transform=None):\n",
    "\n",
    "        self.images_valid = images_valid\n",
    "        self.images_valid_path = list(images_valid.keys())\n",
    "        self.transform = transform\n",
    "        self.target_transform = target_transform\n",
    "\n",
    "    def __len__(self):\n",
    "        return len(self.images_valid.keys())\n",
    "\n",
    "    def __getitem__(self, idx):\n",
    "\n",
    "        try:\n",
    "            img_path = self.images_valid_path[idx]\n",
    "            image = torchvision.io.read_image(img_path)\n",
    "            #print(img_path)\n",
    "            label = self.images_valid[img_path]\n",
    "            #print(label)\n",
    "            if self.transform:\n",
    "                image = self.transform(image)\n",
    "            if self.target_transform:\n",
    "                label = self.target_transform(label)\n",
    "            return image, label\n",
    "        except:\n",
    "            return False\n",
    "\n",
    "def train_loop(dataloader, model, loss_fn, optimizer):\n",
    "    size = len(dataloader.dataset)\n",
    "    for batch, (X, y) in enumerate(dataloader):\n",
    "        # Compute prediction and loss\n",
    "\n",
    "        X = X.to(device)\n",
    "        y = y.to(device)\n",
    "        pred = model(X).to(device)\n",
    "        loss = loss_fn(pred, y)\n",
    "\n",
    "        # Backpropagation\n",
    "        optimizer.zero_grad()\n",
    "        loss.backward()\n",
    "        optimizer.step()\n",
    "        if batch % 20 == 0:\n",
    "            loss, current = loss.item(), batch * len(X)\n",
    "            print(f\"loss: {loss:>7f}  [{current:>5d}/{size:>5d}]\")\n",
    "\n",
    "def test_loop(dataloader, model, loss_fn):\n",
    "    size = len(dataloader.dataset)\n",
    "    num_batches = len(dataloader)\n",
    "    test_loss, correct = 0, 0\n",
    "    with torch.no_grad():\n",
    "        for X, y in dataloader:\n",
    "            X = X.to(device)\n",
    "            y = y.to(device)\n",
    "            pred = model(X).to(device)\n",
    "\n",
    "            test_loss += loss_fn(pred, y).item()\n",
    "            correct += (pred.argmax(1) == y).type(torch.float).sum().item()\n",
    "\n",
    "    test_loss /= num_batches\n",
    "    correct /= size\n",
    "    print(f\"Test Error: \\n Accuracy: {(100*correct):>0.1f}%, Avg loss: {test_loss:>8f} \\n\")\n",
    "\n",
    "def train(loader_train, loader_test, model, loss_fn, optimizer):\n",
    "\n",
    "    for t in range(epochs):\n",
    "        print(f\"Epoch {t+1}\\n-------------------------------\")\n",
    "        train_loop(loader_train, model, loss_fn, optimizer)\n",
    "        test_loop(loader_test, model, loss_fn)\n",
    "    print(\"Done!\")\n",
    "\n",
    "def get_loader():\n",
    "    #target_transform=Lambda(lambda y: torch.zeros(2, dtype=torch.float).scatter_(0, torch.tensor(y), value=1))\n",
    "    transform = get_transform()\n",
    "    images_valid = np.load('images_valid.npy', allow_pickle=True).tolist()\n",
    "    data = ImageDataset(images_valid=images_valid,transform=transform)\n",
    "    data_len = len(data)\n",
    "    train_images = int(data_len*train_ratio)\n",
    "    test_images = data_len-train_images\n",
    "    data_train,data_test = torch.utils.data.random_split(data, (train_images, test_images))\n",
    "    loader_train = DataLoader(data_train, batch_size=batch_size)\n",
    "    loader_test = DataLoader(data_test, batch_size=batch_size)\n",
    "    return loader_train,loader_test"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [
    "#generate_images_valid()\n",
    "\n",
    "model = ViT(\n",
    "    image_size = 256,\n",
    "    patch_size = 32,\n",
    "    num_classes = 2,\n",
    "    dim = 1024,\n",
    "    depth = 6,\n",
    "    heads = 16,\n",
    "    mlp_dim = 2048,\n",
    "    dropout = 0.1,\n",
    "    emb_dropout = 0.1).to(device)\n",
    "\n",
    "\n",
    "# loader_train,loader_test =get_loader()\n",
    "# loss_fn = torch.nn.CrossEntropyLoss()\n",
    "# optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate)\n",
    "# train(loader_train, loader_test, model, loss_fn, optimizer)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "output with shape [1, 256, 256] doesn't match the broadcast shape [3, 256, 256]\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 217 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Expected a non empty file\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 1158 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 104 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 133 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 242 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "output with shape [1, 256, 256] doesn't match the broadcast shape [3, 256, 256]\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "output with shape [1, 256, 256] doesn't match the broadcast shape [3, 256, 256]\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 70 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 232 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Expected a non empty file\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "output with shape [1, 256, 256] doesn't match the broadcast shape [3, 256, 256]\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "not supported for this image mode\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 164 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Warning: unknown JFIF revision number 0.00\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "not supported for this image mode\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 2232 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimension 0\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "not supported for this image mode\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "output with shape [1, 256, 256] doesn't match the broadcast shape [3, 256, 256]\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 259 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 402 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "output with shape [1, 256, 256] doesn't match the broadcast shape [3, 256, 256]\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 1408 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n",
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Corrupt JPEG data: 1 extraneous bytes before marker 0xd9\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>>>>>>>>>>>>>\n",
      "Unsupported image file. Only jpeg and png are currently supported.\n",
      ">>>>>>>>>>>>>>\n"
     ]
    }
   ],
   "source": [
    "transform = get_transform()\n",
    "\n",
    "try:\n",
    "    images_valid = np.load('images_valid.npy', allow_pickle=True).tolist()\n",
    "except:\n",
    "    generate_images_valid()\n",
    "    images_valid = np.load('images_valid.npy', allow_pickle=True).tolist()\n",
    "#images_valid = np.load('images_valid.npy', allow_pickle=True).tolist()\n",
    "data = ImageDataset(images_valid=images_valid,transform=transform)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [],
   "source": [
    "images_valid = np.load('images_valid.npy', allow_pickle=True).tolist()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "24762"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.__len__()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "15\n",
      "16\n",
      "17\n",
      "18\n",
      "19\n",
      "20\n",
      "21\n",
      "22\n",
      "23\n",
      "24\n",
      "25\n",
      "26\n",
      "27\n",
      "28\n",
      "29\n",
      "30\n",
      "31\n",
      "32\n",
      "33\n",
      "34\n",
      "35\n",
      "36\n",
      "37\n",
      "38\n",
      "39\n",
      "40\n",
      "41\n",
      "42\n",
      "43\n",
      "44\n",
      "45\n",
      "46\n",
      "47\n",
      "48\n",
      "49\n",
      "50\n",
      "51\n",
      "52\n",
      "53\n",
      "54\n",
      "55\n",
      "56\n",
      "57\n",
      "58\n",
      "59\n",
      "60\n",
      "61\n",
      "62\n",
      "63\n",
      "64\n",
      "65\n",
      "66\n",
      "67\n",
      "68\n",
      "69\n",
      "70\n",
      "71\n",
      "72\n",
      "73\n",
      "74\n",
      "75\n",
      "76\n",
      "77\n",
      "78\n",
      "79\n",
      "80\n",
      "81\n",
      "82\n",
      "83\n",
      "84\n",
      "85\n",
      "86\n",
      "87\n",
      "88\n",
      "89\n",
      "90\n",
      "91\n",
      "92\n",
      "93\n",
      "94\n",
      "95\n",
      "96\n",
      "97\n",
      "98\n",
      "99\n",
      "100\n",
      "101\n",
      "102\n",
      "103\n",
      "104\n",
      "105\n",
      "106\n",
      "107\n",
      "108\n",
      "109\n",
      "110\n",
      "111\n",
      "112\n",
      "113\n",
      "114\n",
      "115\n",
      "116\n",
      "117\n",
      "118\n",
      "119\n",
      "120\n",
      "121\n",
      "122\n",
      "123\n",
      "124\n",
      "125\n",
      "126\n",
      "127\n",
      "128\n",
      "129\n",
      "130\n",
      "131\n",
      "132\n",
      "133\n",
      "134\n",
      "135\n",
      "136\n",
      "137\n",
      "138\n",
      "139\n",
      "140\n",
      "141\n",
      "142\n",
      "143\n",
      "144\n",
      "145\n",
      "146\n",
      "147\n",
      "148\n",
      "149\n",
      "150\n",
      "151\n",
      "152\n",
      "153\n",
      "154\n",
      "155\n",
      "156\n",
      "157\n",
      "158\n",
      "159\n",
      "160\n",
      "161\n",
      "162\n",
      "163\n",
      "164\n",
      "165\n",
      "166\n",
      "167\n",
      "168\n",
      "169\n",
      "170\n",
      "171\n",
      "172\n",
      "173\n",
      "174\n",
      "175\n",
      "176\n",
      "177\n",
      "178\n",
      "179\n",
      "180\n",
      "181\n",
      "182\n",
      "183\n",
      "184\n",
      "185\n",
      "186\n",
      "187\n",
      "188\n",
      "189\n",
      "190\n",
      "191\n",
      "192\n",
      "193\n",
      "194\n",
      "195\n",
      "196\n",
      "197\n",
      "198\n",
      "199\n",
      "200\n",
      "201\n",
      "202\n",
      "203\n",
      "204\n",
      "205\n",
      "206\n",
      "207\n",
      "208\n",
      "209\n",
      "210\n",
      "211\n",
      "212\n",
      "213\n",
      "214\n",
      "215\n",
      "216\n",
      "217\n",
      "218\n",
      "219\n",
      "220\n",
      "221\n",
      "222\n",
      "223\n",
      "224\n",
      "225\n",
      "226\n",
      "227\n",
      "228\n",
      "229\n",
      "230\n",
      "231\n",
      "232\n",
      "233\n",
      "234\n",
      "235\n",
      "236\n",
      "237\n",
      "238\n",
      "239\n",
      "240\n",
      "241\n",
      "242\n",
      "243\n",
      "244\n",
      "245\n",
      "246\n",
      "247\n",
      "248\n",
      "249\n",
      "250\n",
      "251\n",
      "252\n",
      "253\n",
      "254\n",
      "255\n",
      "256\n",
      "257\n",
      "258\n",
      "259\n",
      "260\n",
      "261\n",
      "262\n",
      "263\n",
      "264\n",
      "265\n",
      "266\n",
      "267\n",
      "268\n",
      "269\n",
      "270\n",
      "271\n",
      "272\n",
      "273\n",
      "274\n",
      "275\n",
      "276\n",
      "277\n",
      "278\n",
      "279\n",
      "280\n",
      "281\n",
      "282\n",
      "283\n",
      "284\n",
      "285\n",
      "286\n",
      "287\n",
      "288\n",
      "289\n",
      "290\n",
      "291\n",
      "292\n",
      "293\n",
      "294\n",
      "295\n",
      "296\n",
      "297\n",
      "298\n",
      "299\n",
      "300\n",
      "301\n",
      "302\n",
      "303\n",
      "304\n",
      "305\n",
      "306\n",
      "307\n",
      "308\n",
      "309\n",
      "310\n",
      "311\n",
      "312\n",
      "313\n",
      "314\n",
      "315\n",
      "316\n",
      "317\n",
      "318\n",
      "319\n",
      "320\n",
      "321\n",
      "322\n",
      "323\n",
      "324\n",
      "325\n",
      "326\n",
      "327\n",
      "328\n",
      "329\n",
      "330\n",
      "331\n",
      "332\n",
      "333\n",
      "334\n",
      "335\n",
      "336\n",
      "337\n",
      "338\n",
      "339\n",
      "340\n",
      "341\n",
      "342\n",
      "343\n",
      "344\n",
      "345\n",
      "346\n",
      "347\n",
      "348\n",
      "349\n",
      "350\n",
      "351\n",
      "352\n",
      "353\n",
      "354\n",
      "355\n",
      "356\n",
      "357\n",
      "358\n",
      "359\n",
      "360\n",
      "361\n",
      "362\n",
      "363\n",
      "364\n",
      "365\n",
      "366\n",
      "367\n",
      "368\n",
      "369\n",
      "370\n",
      "371\n",
      "372\n",
      "373\n",
      "374\n",
      "375\n",
      "376\n",
      "377\n",
      "378\n",
      "379\n",
      "380\n",
      "381\n",
      "382\n",
      "383\n",
      "384\n",
      "385\n",
      "386\n",
      "387\n",
      "388\n",
      "389\n",
      "390\n",
      "391\n",
      "392\n",
      "393\n",
      "394\n",
      "395\n",
      "396\n",
      "397\n",
      "398\n",
      "399\n",
      "400\n",
      "401\n",
      "402\n",
      "403\n",
      "404\n",
      "405\n",
      "406\n",
      "407\n",
      "408\n",
      "409\n",
      "410\n",
      "411\n",
      "412\n",
      "413\n",
      "414\n",
      "415\n",
      "416\n",
      "417\n",
      "418\n",
      "419\n",
      "420\n",
      "421\n",
      "422\n",
      "423\n",
      "424\n",
      "425\n",
      "426\n",
      "427\n",
      "428\n",
      "429\n",
      "430\n",
      "431\n",
      "432\n",
      "433\n",
      "434\n",
      "435\n",
      "436\n",
      "437\n",
      "438\n",
      "439\n",
      "440\n",
      "441\n",
      "442\n",
      "443\n",
      "444\n",
      "445\n",
      "446\n",
      "447\n",
      "448\n",
      "449\n",
      "450\n",
      "451\n",
      "452\n",
      "453\n",
      "454\n",
      "455\n",
      "456\n",
      "457\n",
      "458\n",
      "459\n",
      "460\n",
      "461\n",
      "462\n",
      "463\n",
      "464\n",
      "465\n",
      "466\n",
      "467\n",
      "468\n",
      "469\n",
      "470\n",
      "471\n",
      "472\n",
      "473\n",
      "474\n",
      "475\n",
      "476\n",
      "477\n",
      "478\n",
      "479\n",
      "480\n",
      "481\n",
      "482\n",
      "483\n",
      "484\n",
      "485\n",
      "486\n",
      "487\n",
      "488\n",
      "489\n",
      "490\n",
      "491\n",
      "492\n",
      "493\n",
      "494\n",
      "495\n",
      "496\n",
      "497\n",
      "498\n",
      "499\n",
      "500\n",
      "501\n",
      "502\n",
      "503\n",
      "504\n",
      "505\n",
      "506\n",
      "507\n",
      "508\n",
      "509\n",
      "510\n",
      "511\n",
      "512\n",
      "513\n",
      "514\n",
      "515\n",
      "516\n",
      "517\n",
      "518\n",
      "519\n",
      "520\n",
      "521\n",
      "522\n",
      "523\n",
      "524\n",
      "525\n",
      "526\n",
      "527\n",
      "528\n",
      "529\n",
      "530\n",
      "531\n",
      "532\n",
      "533\n",
      "534\n",
      "535\n",
      "536\n",
      "537\n",
      "538\n",
      "539\n",
      "540\n",
      "541\n",
      "542\n",
      "543\n",
      "544\n",
      "545\n",
      "546\n",
      "547\n",
      "548\n",
      "549\n",
      "550\n",
      "551\n",
      "552\n",
      "553\n",
      "554\n",
      "555\n",
      "556\n",
      "557\n",
      "558\n",
      "559\n",
      "560\n",
      "561\n",
      "562\n",
      "563\n",
      "564\n",
      "565\n",
      "566\n",
      "567\n",
      "568\n",
      "569\n",
      "570\n",
      "571\n",
      "572\n",
      "573\n",
      "574\n",
      "575\n",
      "576\n",
      "577\n",
      "578\n",
      "579\n",
      "580\n",
      "581\n",
      "582\n",
      "583\n",
      "584\n",
      "585\n",
      "586\n",
      "587\n",
      "588\n",
      "589\n",
      "590\n",
      "591\n",
      "592\n",
      "593\n",
      "594\n",
      "595\n",
      "596\n",
      "597\n",
      "598\n",
      "599\n",
      "600\n",
      "601\n",
      "602\n",
      "603\n",
      "604\n",
      "605\n",
      "606\n",
      "607\n",
      "608\n",
      "609\n",
      "610\n",
      "611\n",
      "612\n",
      "613\n",
      "614\n",
      "615\n",
      "616\n",
      "617\n",
      "618\n",
      "619\n",
      "620\n",
      "621\n",
      "622\n",
      "623\n",
      "624\n",
      "625\n",
      "626\n",
      "627\n",
      "628\n",
      "629\n",
      "630\n",
      "631\n",
      "632\n",
      "633\n",
      "634\n",
      "635\n",
      "636\n",
      "637\n",
      "638\n",
      "639\n",
      "640\n",
      "641\n",
      "642\n",
      "643\n",
      "644\n",
      "645\n",
      "646\n",
      "647\n",
      "648\n",
      "649\n",
      "650\n",
      "651\n",
      "652\n",
      "653\n",
      "654\n",
      "655\n",
      "656\n",
      "657\n",
      "658\n",
      "659\n",
      "660\n",
      "661\n",
      "662\n",
      "663\n",
      "664\n",
      "665\n",
      "666\n",
      "667\n",
      "668\n",
      "669\n",
      "670\n",
      "671\n",
      "672\n",
      "673\n",
      "674\n",
      "675\n",
      "676\n",
      "677\n",
      "678\n",
      "679\n",
      "680\n",
      "681\n",
      "682\n",
      "683\n",
      "684\n",
      "685\n",
      "686\n",
      "687\n",
      "688\n",
      "689\n",
      "690\n",
      "691\n",
      "692\n",
      "693\n",
      "694\n",
      "695\n",
      "696\n",
      "697\n",
      "698\n",
      "699\n",
      "700\n",
      "701\n",
      "702\n",
      "703\n",
      "704\n",
      "705\n",
      "706\n",
      "707\n",
      "708\n",
      "709\n",
      "710\n",
      "711\n",
      "712\n",
      "713\n",
      "714\n",
      "715\n",
      "716\n",
      "717\n",
      "718\n",
      "719\n",
      "720\n",
      "721\n",
      "722\n",
      "723\n",
      "724\n",
      "725\n",
      "726\n",
      "727\n",
      "728\n",
      "729\n",
      "730\n",
      "731\n",
      "732\n",
      "733\n",
      "734\n",
      "735\n",
      "736\n",
      "737\n",
      "738\n",
      "739\n",
      "740\n",
      "741\n",
      "742\n",
      "743\n",
      "744\n",
      "745\n",
      "746\n",
      "747\n",
      "748\n",
      "749\n",
      "750\n",
      "751\n",
      "752\n",
      "753\n",
      "754\n",
      "755\n",
      "756\n",
      "757\n",
      "758\n",
      "759\n",
      "760\n",
      "761\n",
      "762\n",
      "763\n",
      "764\n",
      "765\n",
      "766\n",
      "767\n",
      "768\n",
      "769\n",
      "770\n",
      "771\n",
      "772\n"
     ]
    },
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mKeyboardInterrupt\u001B[0m                         Traceback (most recent call last)",
      "\u001B[0;32m/var/folders/g5/fcv40hgd18q84d4wm452cms00000gn/T/ipykernel_90486/3529267048.py\u001B[0m in \u001B[0;36m<module>\u001B[0;34m\u001B[0m\n\u001B[1;32m      3\u001B[0m     \u001B[0mb\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0mc\u001B[0m \u001B[0;34m=\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mdata\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mi\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m      4\u001B[0m     \u001B[0mb\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0munsqueeze_\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;36m0\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m----> 5\u001B[0;31m     \u001B[0ma\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mmodel\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mb\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m      6\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/miniconda3/envs/local/lib/python3.8/site-packages/torch/nn/modules/module.py\u001B[0m in \u001B[0;36m_call_impl\u001B[0;34m(self, *input, **kwargs)\u001B[0m\n\u001B[1;32m   1108\u001B[0m         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks\n\u001B[1;32m   1109\u001B[0m                 or _global_forward_hooks or _global_forward_pre_hooks):\n\u001B[0;32m-> 1110\u001B[0;31m             \u001B[0;32mreturn\u001B[0m \u001B[0mforward_call\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m*\u001B[0m\u001B[0minput\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m**\u001B[0m\u001B[0mkwargs\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m   1111\u001B[0m         \u001B[0;31m# Do not call functions when jit is used\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m   1112\u001B[0m         \u001B[0mfull_backward_hooks\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mnon_full_backward_hooks\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;34m[\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m[\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/miniconda3/envs/local/lib/python3.8/site-packages/vit_pytorch/vit.py\u001B[0m in \u001B[0;36mforward\u001B[0;34m(self, img)\u001B[0m\n\u001B[1;32m    122\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    123\u001B[0m         \u001B[0mx\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mto_latent\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mx\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 124\u001B[0;31m         \u001B[0;32mreturn\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mmlp_head\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mx\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m",
      "\u001B[0;32m/opt/miniconda3/envs/local/lib/python3.8/site-packages/torch/nn/modules/module.py\u001B[0m in \u001B[0;36m_call_impl\u001B[0;34m(self, *input, **kwargs)\u001B[0m\n\u001B[1;32m   1108\u001B[0m         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks\n\u001B[1;32m   1109\u001B[0m                 or _global_forward_hooks or _global_forward_pre_hooks):\n\u001B[0;32m-> 1110\u001B[0;31m             \u001B[0;32mreturn\u001B[0m \u001B[0mforward_call\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m*\u001B[0m\u001B[0minput\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m**\u001B[0m\u001B[0mkwargs\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m   1111\u001B[0m         \u001B[0;31m# Do not call functions when jit is used\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m   1112\u001B[0m         \u001B[0mfull_backward_hooks\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mnon_full_backward_hooks\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;34m[\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m[\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/miniconda3/envs/local/lib/python3.8/site-packages/torch/nn/modules/container.py\u001B[0m in \u001B[0;36mforward\u001B[0;34m(self, input)\u001B[0m\n\u001B[1;32m    139\u001B[0m     \u001B[0;32mdef\u001B[0m \u001B[0mforward\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0minput\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    140\u001B[0m         \u001B[0;32mfor\u001B[0m \u001B[0mmodule\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 141\u001B[0;31m             \u001B[0minput\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mmodule\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0minput\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    142\u001B[0m         \u001B[0;32mreturn\u001B[0m \u001B[0minput\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    143\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/miniconda3/envs/local/lib/python3.8/site-packages/torch/nn/modules/module.py\u001B[0m in \u001B[0;36m_call_impl\u001B[0;34m(self, *input, **kwargs)\u001B[0m\n\u001B[1;32m   1108\u001B[0m         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks\n\u001B[1;32m   1109\u001B[0m                 or _global_forward_hooks or _global_forward_pre_hooks):\n\u001B[0;32m-> 1110\u001B[0;31m             \u001B[0;32mreturn\u001B[0m \u001B[0mforward_call\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m*\u001B[0m\u001B[0minput\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m**\u001B[0m\u001B[0mkwargs\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m   1111\u001B[0m         \u001B[0;31m# Do not call functions when jit is used\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m   1112\u001B[0m         \u001B[0mfull_backward_hooks\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mnon_full_backward_hooks\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0;34m[\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m[\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;32m/opt/miniconda3/envs/local/lib/python3.8/site-packages/torch/nn/modules/linear.py\u001B[0m in \u001B[0;36mforward\u001B[0;34m(self, input)\u001B[0m\n\u001B[1;32m    101\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    102\u001B[0m     \u001B[0;32mdef\u001B[0m \u001B[0mforward\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0minput\u001B[0m\u001B[0;34m:\u001B[0m \u001B[0mTensor\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;34m->\u001B[0m \u001B[0mTensor\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 103\u001B[0;31m         \u001B[0;32mreturn\u001B[0m \u001B[0mF\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mlinear\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0minput\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mweight\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mself\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mbias\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m    104\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m    105\u001B[0m     \u001B[0;32mdef\u001B[0m \u001B[0mextra_repr\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mself\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;34m->\u001B[0m \u001B[0mstr\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n",
      "\u001B[0;31mKeyboardInterrupt\u001B[0m: "
     ]
    }
   ],
   "source": [
    "for i in range(len(data)):\n",
    "    print(i)\n",
    "    b,c =(data[i])\n",
    "    b.unsqueeze_(0)\n",
    "    a = model(b)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [],
   "source": [
    "images_valid = np.load('images_valid.npy', allow_pickle=True).tolist()\n",
    "data = ImageDataset(images_valid=images_valid,transform=transform)\n",
    "loader = DataLoader(data)\n",
    "len(data)\n",
    "images_path = list(images_valid.keys())"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/opt/miniconda3/envs/local/lib/python3.8/site-packages/PIL/TiffImagePlugin.py:822: UserWarning: Truncated File Read\n",
      "  warnings.warn(str(msg))\n"
     ]
    }
   ],
   "source": [
    "import PIL\n",
    "for absolute_path in images_path:\n",
    "        try:\n",
    "            img = PIL.Image.open(absolute_path)\n",
    "        except IOError:\n",
    "            print(absolute_path)\n",
    "        try:\n",
    "            img= np.asarray(img)\n",
    "        except :\n",
    "            print('corrupt img',absolute_path)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "from PIL import Image"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [],
   "source": [
    "a = Image.open(\"/Users/leslie/Desktop/1.png\")\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "data": {
      "text/plain": "(780, 1134)"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.size\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [],
   "source": [
    "a = a.resize((390,567))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "data": {
      "text/plain": "(390, 567)"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a.size"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [],
   "source": [
    "a.save(\"1.jpg\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [
     "\n"
    ],
    "metadata": {
     "collapsed": false
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}